#! /bin/bash

IP_HOST=""

echo "Connect phone And Press Enter: "
read

adb root
adb wait-for-device
adb remount
adb wait-for-device

echo "Enable 'USB Thether' And Press Enter: "
read

adb wait-for-device

set -x
# host side
IP_HOST=$(ifconfig usb0 | grep "inet addr:" | sed -r 's/ +/ /g' | awk -F"[: ]" '{print $4}')
sudo su -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo su -c "iptables -t nat -F"
sudo su -c "iptables -t nat -A POSTROUTING -j MASQUERADE"

# device side
adb shell su -c route add default gw $IP_HOST dev rndis0
adb shell ping -c 2 www.baidu.com
set -
